package com.xcc.netty.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author frosty
 * @description
 * @date 2019-12-30 30:09:24
 */


public class MyServer {

    public static void main(String[] args) throws  Exception{
         server();
    }

    public  static void   server() throws IOException {
        ServerSocket socket=new ServerSocket(8761);
         while (true){
              Socket accept = socket.accept();
             OutputStream outputStream = accept.getOutputStream();
             outputStream.write("success".getBytes());
             InputStream inputStream=accept.getInputStream();
             byte[] buff=new byte[10];
             System.out.println(Thread.currentThread().getId());
             int len=0;
              while ((len=inputStream.read(buff))!=-1){
                  String s=new String(buff,0,len,"gbk");
                  System.out.println("客户端消息"+s);
                  outputStream.write("成功".getBytes("gbk"));
               //   outputStream.flush();
              }


         }

    }

}
